﻿#region

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

#endregion

namespace Vin.Extension.Framework;

[Order(0)]
public class ExtensionEntry : IVinExtension
{
    public void AddVinExtension(WebApplicationBuilder builder)
    {
        if (!VinFrameworkExtension.IsInit)
        {
            throw new System.Exception(
                "请先初始化 VinFrameworkExtension，在builder初始化前调用（为避免程序发生不必要的麻烦，建议放到CreateBuilder之前），程序启动只能调用一次");
        }
    }

    public void AddVinExtension(IServiceCollection services)
    {
        // 添加响应压缩服务
        services.AddResponseCompression(options =>
        {
            options.EnableForHttps = true; // 启用HTTPS下的压缩
        });
    }

    public void UseVinExtensionBefore(WebApplication app)
    {
        // 使用响应压缩中间件
        app.UseResponseCompression();
    }

    public void UseVinExtension(WebApplication app)
    {
    }
}